/**
 * 
 */
package truerefactor.codesmell;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import truerefactor.graph.ClassNode;
import truerefactor.graph.CodeGraph;
import truerefactor.refactor.Refactoring;

/**
 * @author Isaac
 */
public class SpeculativeGenerality extends CodeSmell {

    /**
     * 
     */
    public SpeculativeGenerality()
    {
        this.shortName = "SPECGEN";
        this.name = "Speculative Generality";
        this.description = "";
    }

    /*
     * (non-Javadoc)
     * @see
     * truerefactor.codesmell.CodeSmell#measure(truerefactor.graph.CodeGraph,
     * boolean, java.util.List)
     */
    @Override
    protected double measure(CodeGraph graph, boolean initial, List<List<Refactoring>> sequences)
    {
        List<ClassNode> classes = graph.getClasses();
        double specGen = 0;

        List<ClassNode> possibles = new ArrayList<ClassNode>();
        for (ClassNode cNode : classes)
        {
            if (cNode.isAbstract() || cNode.isInterface())
                possibles.add(cNode);
        }
        
        Iterator<ClassNode> possIter = possibles.listIterator();
        while(possIter.hasNext()) {
            ClassNode next = possIter.next();
            if (next.getSubClasses().isEmpty()) {
                specGen++;
            }
        }
        
        return specGen;
    }
}
